open BUFF,"test_graph" or die "no file exists\n";
open(WRBUFF,">oout_test_graph");
while($line = <BUFF>)
{
	chomp($line);
if($line =~ m/\d/)
{
	$line =~ s/\s+/\t/g;
	$line =~ s/\t+/\t/g;
	@array = split("\t",$line);
	@bin = split("_",$array[0]);
	$binstart = $bin[1];
	@exon = split("__",$array[1]);
	#print $binstart."\t".$exon[0]."\n";	
	@cord = split("_",$exon[0]);
	$exonstart = $cord[@cord-2];
	$exonstop = $cord[@cord-1];
	$gene = $cord[0];
	$dist_exon = abs($exonstart -$exonstop);
	if($exon[0] =~ m/exon/)
	{
		
		if(abs($binstart-$exonstart) < abs($binstart-$exonstop))
		{
			$dist = abs($binstart-$exonstart);
			$ind = "5'";
		}
		else
		{
			$dist = abs($binstart-$exonstop);
			$ind = "3'";
		}	
	}
	else
	{
		$temp = $exonstop;
		$exonstop = $exonstart;
		$exonstart = $temp;
		 if(abs($binstart-$exonstart) < abs($binstart-$exonstop))
                {
                        $dist = abs($binstart-$exonstart);
                        $ind = "5'";
                }
                else
                {
                        $dist = abs($binstart-$exonstop);
                        $ind = "3'";
                }
		

	}
	if($dist_exon == 0)
	{
	$percent = 0;
	}
	else
	{
	$percent = ($dist/$dist_exon)*100;
	}
	print $line."\t".$gene."\t".$dist."\t".$ind."\t$dist_exon\t$percent\n";
}
}
